package com.tensquare.controller;

import org.springframework.http.HttpStatus;

import com.tensquare.entity.Result;

public class BaseController {
	public Result setResultError(Integer code,String msg) {
		return setResult(code, msg, null);
	}
	// 返回错误，可以传msg
	public Result setResultError(String msg) {
		return setResult(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg, null);
	}

	// 返回成功，可以传data值
	public Result setResultSuccess(Object data) {
		return setResult(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), data);
	}

	// 返回成功，沒有data值
	public Result setResultSuccess() {
		return setResult(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), null);
	}

	// 返回成功，沒有data值
	public Result setResultSuccess(String msg) {
		return setResult(HttpStatus.OK.value(), msg, null);
	}

	// 通用封装
	public Result setResult(Integer code, String msg, Object data) {
		return new Result(code, msg, data);
	}
}
